﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;

namespace work5_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)//file1
        {
            OpenFileDialog fd = new OpenFileDialog();//创建（打开）一个文件对话框
            fd.InitialDirectory = "C:\\Users\\29339\\Desktop\\大二下\\软件构造基础\\work5";//对话框的初始目录
            fd.Filter = "文本文件|*.txt";//设置打开文件的类型，即文件筛选器
            fd.ShowDialog();//打开选择文件对话框
            string path1 = fd.FileName;//获取打开的文件名
            label1.Text = path1;//路径显示在标签上
        }

        private void button2_Click(object sender, EventArgs e)//file2和file1类似
        {
            OpenFileDialog fd = new OpenFileDialog();
            fd.InitialDirectory = "C:\\Users\\29339\\Desktop\\大二下\\软件构造基础\\work5";
            fd.Filter = "文本文件|*.txt";
            fd.ShowDialog();
            string path2 = fd.FileName;
            label2.Text = path2;
        }

        private void button3_Click(object sender, EventArgs e)//combine
        {//DirectoryInfo 类.公开用于创建、移动和枚举目录和子目录的实例方法。
            DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Users\29339\Desktop\大二下\软件构造基础\work5");
            if (!directoryInfo.Exists)
            {
                directoryInfo.Create();
            }
            string directoryPath = directoryInfo.ToString();
            string fileName = "3.txt";
            String filePath = Path.Combine(directoryPath, fileName);//合并两个路径字符串
            using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Write))
            {

            }
            string[] textOfFile1 = File.ReadAllLines(label1.Text);
            string[] textOfFile2 = File.ReadAllLines(label2.Text);
            File.AppendAllLines(filePath, textOfFile1);//在combine.text文件中加入text of file1
            File.AppendAllLines(filePath, textOfFile2);//在combine.text文件中加入text of file2
            label3.Text = Path.GetFullPath(filePath);//获取全路径
            ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();

            //设置启动进程的初始目录
            info.WorkingDirectory = Application.StartupPath;
            //设置启动进程的应用程序或文档名
            info.FileName = @"C:\Users\29339\Desktop\大二下\软件构造基础\work5\3.txt";
            //设置启动进程的参数
            info.Arguments = "";
            //启动进程
            Process.Start(info);
        }
    }
}
